/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.managed;

import com.model.Departamento;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.hibernate.SessionFactory;

/**
 *
 * @author Emerson
 */
@ManagedBean
@SessionScoped
public class ManagedBeanDep {

    /** Creates a new instance of ManagedBeanDep */
    private Departamento dep = new Departamento();
    private String Error;
    private Helper help;
    
    public ManagedBeanDep() {
        help = new Helper();
    }

    public String saveDepartamento(){
        try {
            help.iniciarTransaccion();
            help.salvarObjeto(dep);
            help.confirmarTransaction();
            help.cerrarTransaction();
            dep = new Departamento();
            return "welcomeICEfaces";
        } catch (Exception e) {
            Error = e.getMessage();
            return "errorPage";
        }
    }

    public Departamento getDep() {
        return dep;
    }

    public void setDep(Departamento dep) {
        this.dep = dep;
    }

    public String getError() {
        return Error;
    }

    public void setError(String Error) {
        this.Error = Error;
    }
}
